package com.qf.controller;

import com.qf.pojo.Music;
import com.qf.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class MusicController {
    @Autowired
    MusicService musicService;
    @RequestMapping("/findMusicAll")
    public List<Music> findAll(){
        return  musicService.findAll();
    }
    @RequestMapping("/findMusicById")
    public Music findById(@RequestBody Map map){
        Object ids = map.get("id");
        String id=(String)ids;
        return musicService.findById(Integer.valueOf(id));
    }
    @RequestMapping("/deleteMusicById")
    public String deleteById(@RequestBody Map map){
        try {
            Object ids = map.get("id");
            Integer id=(Integer)ids;
            musicService.deleteByid(id);
        }catch (Exception e){
            return "fail";
        }
        return "success";
    }
    @RequestMapping("/saveAndUpdateMusic")
    public String savaAndUpdate(@RequestBody Music music){
        try {
            musicService.saveAndUpdateMusic(music);
        }catch (Exception e){
            return "fail";
        }
        return "success";
    }
    @RequestMapping("/findMusicByName")
    public List<Music> findMusicByMname(@RequestBody Map map){
        String name = (String)map.get("name");
        return musicService.findMusicByMname(name);
    }
    @RequestMapping("/findMusicByMusicer")
    public List<Music> findMusicByMusicer(@RequestBody Map map){
        String auther=(String)map.get("auther");
        return musicService.findMusicByMusicer(auther);
    }
    @RequestMapping("/findMusicByCla")
    public List<Music> findMusicByCla(@RequestBody Map map){
        String cla=(String) map.get("cla");
        return musicService.findMusicByCla(cla);
    }
    @RequestMapping("/findMusicByCStyle")
    public List<Music> findMusicByCStyle(@RequestBody Map map){
        String cstyle=(String) map.get("cstyle");
        return musicService.findMusicByCla(cstyle);
    }
    @RequestMapping("/findMusicByChangJing")
    public List<Music> findMusicByChangJing(@RequestBody Map map){
        String changjing=(String) map.get("changjing");
        return musicService.findMusicByCla(changjing);
    }
    @RequestMapping("/findMusicByQingGan")
    public List<Music> findMusicByQingGan(@RequestBody Map map){
        String qinggan=(String) map.get("qinggan");
        return musicService.findMusicByCla(qinggan);
    }
    @RequestMapping("/findMusicByZhuTi")
    public List<Music> findMusicByZhuTi(@RequestBody Map map){
        String zhuti=(String) map.get("zhuti");
        return musicService.findMusicByCla(zhuti);
    }
    @RequestMapping("/findMusicByMName")
    public List<Music> findMusicByMName(@RequestBody Map map){
        String mname=(String) map.get("mname");
        return musicService.findMusicByCla(mname);
    }
    @RequestMapping("/findMusicByCdName")
    public List<Music> findMusicByCdName(@RequestBody Map map){
        String cdname=(String) map.get("cdname");
        return musicService.findMusicByCla(cdname);
    }
    @RequestMapping("findMusicByUid")
    public List<Music> findMusicByUid(@RequestBody Map map){
        Integer uid=(Integer)map.get("Uid");
        return musicService.findMusicByUid(uid);
    }
}
